package com.ninth_group.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.ninth_group.exception.province.ProvinceNameIsValidException;
import com.ninth_group.result.R;
import com.ninth_group.service.PCService;
import com.ninth_group.vo.ProvinceCitiesVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 一个省份的所有城市天气信息
 */
@RestController
@RequestMapping("/pCity/{pName}")
public class PCController {
    @Resource
    private PCService pcService;

    @GetMapping
    public R getPCWeatherInfo(@PathVariable String pName) throws JsonProcessingException {
        System.out.println("PCController 接口 -> 前端获取的省份名称: " + pName);
        List<ProvinceCitiesVO> pcWeatherInfo = pcService.getPCWeatherInfo(pName);
        return R.ok("获取成功", pcWeatherInfo);
    }

    @ExceptionHandler(ProvinceNameIsValidException.class)
    public R handleProvinceNameIsValidException(ProvinceNameIsValidException e) {
        return R.error(e.getMessage());
    }
}
